package com.coocaa.x.service.litecontent.providers.store.host.com_coocaa_appstore;

import android.content.Context;
import android.net.Uri;

import com.coocaa.x.framework.app.CoocaaApplication;
import com.coocaa.x.framework.utils.Android;
import com.coocaa.x.service.litecontent.LiteContentProvider;
import com.coocaa.x.service.litecontent.LiteContentProvider.LiteContentProviderHost;
import com.coocaa.x.service.litecontent.LiteContentProvider.ResourceHandler;
import com.coocaa.x.service.litecontent.data.ResultPackage;
import com.coocaa.x.service.litecontent.data.store.com_coocaa_apptore.RP_New_Apps;
import com.coocaa.x.service.litecontent.data.store.com_coocaa_apptore.RP_New_Apps.AppStatNum;
import com.skyworth.logsdk.appstore.LogAPIForAppStore;
import com.skyworth.webSDK.webservice.tcappstore.AppStatNumBean;

public class StoreHost_Com_Coocaa_appstore extends LiteContentProviderHost {
    private static StoreHost_Com_Coocaa_appstore instance = null;

    public static synchronized void create(Context context, LiteContentProvider provider) {
        if (instance == null)
            instance = new StoreHost_Com_Coocaa_appstore(context, provider);
    }

    private static final String MY_HOST = "com.coocaa.appstore";


    public StoreHost_Com_Coocaa_appstore(Context context, LiteContentProvider provider) {
        super(context, provider);
        // TODO Auto-generated constructor stub
    }

    @Override
    public String myHost() {
        // TODO Auto-generated method stub
        return MY_HOST;
    }

    private ResourceHandler mainpageHandler = new ResourceHandler(this, "/newnums") {
        private AppStatNum getNewAppNumFromWeb() {
            try {
                AppStatNumBean data = CoocaaApplication.getCoocaaWebService().getAppStoreService().getNewAppCount();
                return new AppStatNum(data.count, data.updateTime);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                LogAPIForAppStore.reportInterfaceError("获取应用圈最新推荐应用个数", Android.throwable2String(e));
                e.printStackTrace();
                return new AppStatNum();
            }
        }

        @Override
        public ResultPackage call(Uri uri) {
            // TODO Auto-generated method stub
            RP_New_Apps rp = new RP_New_Apps();
            AppStatNum num = getNewAppNumFromWeb();
            rp.resource.add(num);
            return rp;
        }

    };


}
